package com.dwzlab.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.dwzlab.vo.XUser;


public class DBTool {
	private final String driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
//	private final String url = "jdbc:sqlserver://192.168.30.40:1433;DatabaseName=qtytemp;SelectMethod=cursor;";
	private final String url = "jdbc:sqlserver://192.168.1.6;instanceName=WMS;databaseName=guoliwms;SelectMethod=cursor;";
	private final String user = "sa";
	private final String pasd = "111111";
	public void showResults(){
		Connection conn = null;
		try {
			Class.forName(driverClassName);
			conn = DriverManager.getConnection(url, user, pasd);
			BeanHandler<XUser> xuserBean = new BeanHandler<XUser>(XUser.class);
			QueryRunner qRunner = new QueryRunner();
			String sql = "select id,e_name from t_b_employee where id = ?";
			XUser xUser = qRunner.query(conn, sql, xuserBean, 2);
			System.out.println(xUser);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				DbUtils.close(conn);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) {
		DBTool dbTool = new DBTool();
		dbTool.showResults();
	}
}
